#include "../comm.h"
class Solution {
public:
    int C2(int x)
    {
        return x > 0 ? (x - 1) * x / 2 : 0;
    }
    int distributeCandies(int n, int limit) {
        // 容斥原理
        return C2(n + 2) - 3 * C2(n - limit + 1) + 3 * C2(n - 2 * limit) - C2(n - 3 * limit - 1);

    }
};